package com.example.lc.mythreedemo.custom;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.example.lc.mythreedemo.ImageCycleView;

/**
 * 首页11层楼中的viewpage
 */
public class MyViewPage extends ViewPager {
    private ImageCycleView imagecycleview;
    public MyViewPage(Context context) {
        super(context);
    }

    public MyViewPage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_MOVE:
                if (imagecycleview.isAutoCycle) {
                    // 停止图片滚动
                    imagecycleview.stopImageCycle();
                }
                break;
            case MotionEvent.ACTION_CANCEL:
                if (imagecycleview.isAutoCycle) {
                    // 开始图片滚动
                    imagecycleview.startImageCycle();
                }
                break;
            case MotionEvent.ACTION_UP:
                if (imagecycleview.isAutoCycle) {
                    // 开始图片滚动
                    imagecycleview.startImageCycle();
                }
                break;

        }
        return super.dispatchTouchEvent(ev);
    }

    /**
     * 赋值不能不赋
     * @param imagecycleview
     */
    public void setImagecycleview(ImageCycleView imagecycleview) {
        this.imagecycleview = imagecycleview;
    }
}
